package pl.edu.agh.io.fx3.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public abstract class ChecksumGenerator {
	public static String getChecksum(String string1, String string2) {
		StringBuffer sb = new StringBuffer();
		
		try {
			byte[] bytesOfMessage = (string1+string2).getBytes("UTF-8");
	
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] thedigest = md.digest(bytesOfMessage);
	
	        for (int i = 0; i < thedigest.length; i++) {
	        	sb.append(Integer.toString((thedigest[i] & 0xff) + 0x100, 16).substring(1));
	        }
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return String.valueOf((string1+string2).hashCode());
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return String.valueOf((string1+string2).hashCode());
		}
        
        return sb.toString();
	}
}
